package com.preskool.service.impl;

import com.preskool.service.StudentService;
import com.preskool.mapper.StudentMapper;
import com.preskool.po.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther
 * @Date
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired(required = false)
    private StudentMapper studentMapper;

    //通过id单查
    @Override
    public Student selectById(Integer id) {
        Student student = studentMapper.selectByPrimaryKey(id);
        return student;
    }

    //添加学生
    @Override
    public Boolean addStudent(Student student) {
        int i = studentMapper.insertSelective(student);
        if (i>0){
            return true;
        }else{
            return false;
        }
    }

    //通过id删除学生
    @Override
    public Boolean deleteStudent(Integer id) {
        int i = studentMapper.deleteByPrimaryKey(id);
        if (i>0){
            return true;
        }else{
            return false;
        }
    }

    //通过id修改学生
    @Override
    public Boolean updateStudent(Integer id) {
        int i = studentMapper.updateByPrimaryKeySelective(id);
        if (i>0){
            return true;
        }else{
            return false;
        }
    }

    //分页查询
    @Override
    public List<Student> findPage(Integer currentPage,Integer pageSize) {
        List<Student> students = studentMapper.findAll(currentPage, pageSize);
        if (students!=null){
            return students;
        }else{
            return null;
        }
    }
}
